package nkr1pt.popkorn.exceptions;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Kristof Vanhaeren
 */
public class ExceptionHandler {

    private static final Logger logger = Logger.getLogger(ExceptionHandler.class.getName());

    public void handleException(UnrecoverableException e) {
        logger.log(Level.SEVERE, "An unrecoverable exception occurred, Popkorn cannot proceed.");
        logger.log(Level.SEVERE, e.getMessage());
        System.exit(0);
    }

    public void handleException(RecoverableException e) {
        logger.log(Level.WARNING, "An exception occurred, but popkorn is able to proceed.");
        logger.log(Level.WARNING, e.getMessage());
    }

    public void handleException(Throwable t) {
        if (t instanceof UnrecoverableException) {
            handleException((RecoverableException)t);
        } else if (t instanceof RecoverableException) {
            handleException((RecoverableException)t);
        } else {
            logger.log(Level.SEVERE, "An unrecoverable exception occurred, Popkorn cannot proceed.");
            logger.log(Level.SEVERE, t.getMessage());
            System.exit(0);
        }
    }
}